<!--
 * @Author: liujiachen liujiachen@neuedu.com
 * @Date: 2024-09-12 17:29:04
 * @LastEditors: liujiachen liujiachen@neuedu.com
 * @LastEditTime: 2024-09-17 13:20:52
 * @FilePath: \WWW\notepad\UserLogin.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Notepad</title>

    <!-- bootstrap -->
    <link rel="stylesheet" href="./assets/css/bootstrap.min.css" />

    <!-- animate.css -->
    <link rel="stylesheet" href="./assets/css/animate.min.css" />
    
    <!-- 重置样式 -->
    <link rel="stylesheet" href="./assets/css/reset.css" />

    <!-- 公共样式 -->
    <link rel="stylesheet" href="./assets/css/common.css" />

    <!-- 页面独立的 -->
    <link rel="stylesheet" href="./assets/css/UserLogin.css" />
    <!-- 引入mui框架 -->
    <link rel="stylesheet" href="./assets/plugins/mui/css/mui.min.css">

    
</head>
<body>
    <!-- 用户信息 -->
    <div class="user">
        <div class="avatar wow fadeInUp">
            <img src="./assets/images/avatar.png" />
        </div>

        <div class="notice wow fadeInUp" data-wow-delay="100ms">登录/注册界面</div>
    </div>

    <form method="post" id="login" class="login wow fadeInUp" data-wow-delay="200ms">
        <div class="form-group">
            <label for="mobile">手机号码:</label>
            <input type="text" class="form-control" name="mobile" id="mobile" placeholder="请输入邮箱" required />
        </div>

        <div class="form-group">
            <label for="password">密码:</label>
            <input type="password" class="form-control" name="password" id="password" placeholder="请输入密码" required />
        </div>
        
        <div class="action">
            <button type="submit" class="btn">登录</button>
        </div>
    </form>
</body>
</html>
<!-- jquery  -->
<script src="./assets/js/jquery.min.js"></script>

<!-- bootstrap -->
<script src="./assets/js/bootstrap.min.js"></script>
<!-- wow.js -->
<script src="./assets/js/wow.min.js"></script>
<!-- 引入mui的js文件 -->
<script src="./assets/plugins/mui/js/mui.min.js"></script>

<!-- 引入请求封装库 -->
<script src="./assets/plugins/axios/axios.min.js"></script>
<script src="./assets/plugins/axios/request.js"></script>
<!-- 引入cookie文件 -->
<script src="./assets/plugins/cookie.js"></script>

<script>
    //实例化wow.js
    new WOW().init();
    $("#login").submit(async function(e){
        // 阻止表单的默认行文
        e.preventDefault();
         //获取手机号的输入值
        var mobile = $.trim($("#mobile").val());
        var password = $.trim($("#password").val());
        // 正则判断
        var res = /^1[3-9]\d{9}/;
        // console.log(mobile)
        // console.log(res.test(mobile))
        if(!res.test(mobile))
        {
            // mui.toast();自动消失
            mui.alert('手机号码格式不正确','登录注册提醒',['确认']);
            return false;
        }
        if(!password)
        {
            mui.alert('请输入密码!');
            return false;
        }
        var result = await POST({
            url:'/business/login',
            params:{mobile,password}
        })
        
        if(result.code){

            cookie.set('business',JSON.stringify(result.data));
            mui.toast(result.msg,{duration:1000});

            setTimeout(()=>{
                location.href = 'UserIndex.html';
            },1000)
            return false;
        }else{
            mui.alert(result.msg);
            return false;
        }
    })  
    
</script>